# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
from django.conf import settings

from django.contrib import admin
import skoolmaster
admin.autodiscover()

urlpatterns = patterns('',
  # admin
  (r'^admin/', include(admin.site.urls)),    
  
  # Default page is the login page
  url(r'^$', 'skoolmaster.general.views.login'),
  
  # Authentication
  url(r'^login$', 'skoolmaster.general.views.login', name = 'login'),
  url(r'^logout$', 'django.contrib.auth.views.logout_then_login', name = 'logout'),
  
  # Welcome page
  url(r'^welcome$', 'skoolmaster.general.views.welcome', name = 'welcome'),
  
  # Student search
  url(r'^students/search$', 'skoolmaster.general.views.student_search', name = 'student_search'),
  
  # Reports
  url(r'^reports/per_subject$', 'skoolmaster.syllabus.views.report_subject', name = 'report_subject'),
  url(r'^reports/enrolled$', 'skoolmaster.syllabus.views.report_enrolled', name = 'report_enrolled'),

  # Exams 
  url(r'^exams$', 'skoolmaster.exams.views.exam_signup', name = 'exam_signup'),
  url(r'^exams/results/(?P<type>(grades|points|apps))$', 'skoolmaster.exams.views.exam_results', name = 'exam_results'),
  url(r'^exams/results/(?P<type>(grades|points|apps))/dates/(?P<subject>\d+)$', 'skoolmaster.exams.views.exam_results', name = 'exam_results_dates'),
  url(r'^exams/results/(?P<type>(grades|points|apps))/grades/(?P<exam>\d+)$', 'skoolmaster.exams.views.exam_results', name = 'exam_results_display'),
  url(r'^exams/(?P<exam>\d+)/signout$', 'skoolmaster.exams.views.exam_signout', name = 'exam_signout'),

  url(r'^exams_admin$', 'skoolmaster.exams.views.exam_signup_admin', name = 'exam_signup_admin_start'),
  url(r'^exams_admin/(?P<student>\d+)/$', 'skoolmaster.exams.views.exam_signup_admin', name = 'exam_signup_admin'), 
  url(r'^exams_admin/(?P<exam>\d+)/(?P<student>\d+)/signout$', 'skoolmaster.exams.views.exam_signout_admin', name = 'exam_signout_admin'),

  url(r'^exams/list$', 'skoolmaster.exams.views.exam_list', name = 'exam_list'),  
  url(r'^exams/list/(?P<student_number>\d+)$', 'skoolmaster.exams.views.exam_list', name = 'exam_list'),
  url(r'^exams/list/(?P<student_number>\d+)/(?P<printout>(all|last))$', 'skoolmaster.exams.views.exam_list', name = 'exam_list'),

  url(r'^exams/insert$', 'skoolmaster.exams.views.exam_insert', name = 'exam_insert'),
  url(r'^exams/insert/(?P<subject>\d+)$', 'skoolmaster.exams.views.exam_insert', name = 'exam_insert_form'),
  
  url(r'^exams/edit$', 'skoolmaster.exams.views.exam_edit', name = 'exam_edit'),
  url(r'^exams/edit/(?P<subject>\d+)$', 'skoolmaster.exams.views.exam_edit', name = 'exam_edit'),
  url(r'^exams/edit/(?P<subject>\d+)/(?P<exam>\d+)$', 'skoolmaster.exams.views.exam_edit', name = 'exam_edit'),
  
  url(r'^exams/delete$', 'skoolmaster.exams.views.exam_delete', name = 'exam_delete'),
  url(r'^exams/delete/(?P<subject>\d+)$', 'skoolmaster.exams.views.exam_delete', name = 'exam_delete'),
  url(r'^exams/delete/(?P<subject>\d+)/(?P<exam>\d+)$', 'skoolmaster.exams.views.exam_delete', name = 'exam_delete'),
  
  url(r'^exams/grades$', 'skoolmaster.exams.views.exam_insert_grades', name = 'exam_grades'),
  url(r'^exams/grades/(?P<subject>\d+)$', 'skoolmaster.exams.views.exam_insert_grades', name = 'exam_grades_dates'),
  url(r'^exams/grades/insert/(?P<exam>\d+)$', 'skoolmaster.exams.views.exam_insert_grades', name = 'exam_grades_insert'),
  
  url(r'^exams/finalgrades$', 'skoolmaster.exams.views.exam_insert_finalgrades', name = 'exam_finalgrades'),
  url(r'^exams/finalgrades/(?P<subject>\d+)$', 'skoolmaster.exams.views.exam_insert_finalgrades', name = 'exam_finalgrades_dates'),
  url(r'^exams/finalgrades/insert/(?P<exam>\d+)$', 'skoolmaster.exams.views.exam_insert_finalgrades', name = 'exam_finalgrades_insert'),
  
  url(r'^exams/manual_application$', 'skoolmaster.exams.views.exam_manual_application', name = 'exam_manual'),
  url(r'^exams/manual_application/(?P<student>\d+)$', 'skoolmaster.exams.views.exam_manual_application', name = 'exam_manual_subjects'),
  url(r'^exams/manual_application/(?P<student>\d+)/(?P<subject>\d+)$', 'skoolmaster.exams.views.exam_manual_application', name = 'exam_manual_app'),
      
  # Displaying student's grades
  url(r'^student/grades$', 'skoolmaster.exams.views.student_grades', name = 'student_grades'),
  url(r'^student/grades/(?P<student_id>\d+)$', 'skoolmaster.exams.views.student_grades', name = 'student_grades'),
  url(r'^student/grades/(?P<student_id>\d+),(?P<exam_id>\d+)$', 'skoolmaster.exams.views.student_grades', name = 'student_grades'),
      
  # Codelist management
  url(r'^codelists$', 'skoolmaster.general.views.codelist_edit', name = 'codelists'),
  url(r'^codelists/(?P<codelist>[a-zA-Z0-9]+)/(?P<action>(edit|add))$', 'skoolmaster.general.views.codelist_edit', name = 'codelist_action'),
  url(r'^codelists/(?P<codelist>[a-zA-Z0-9]+),(?P<code>[a-zA-Z0-9]+)/(?P<action>(del|edit))/ret=(?P<ret>.*)$', 'skoolmaster.general.views.code_edit', name = 'code_action'),
  
  # Subjects list
  url(r'^subjectlist$', 'skoolmaster.general.views.subjects_list', name = 'subjects_list'),
  url(r'^subjectlist/(?P<school_year>[0-9]{4}/[0-9]{4})$', 'skoolmaster.general.views.subjects_list', name = 'subjects_list'),
  url(r'^subjectlist/(?P<school_year>[0-9]{4}/[0-9]{4})/(?P<program_id>[a-zA-Z0-9]{4})$', 'skoolmaster.general.views.subjects_list', name = 'subjects_list'),
  
  # Managing lecturers
  url(r'^lecturers$', 'skoolmaster.syllabus.views.lecturers', name = 'lecturers'),
  url(r'^lecturers/(?P<subject_id>[a-zA-Z0-9]+)$', 'skoolmaster.syllabus.views.lecturers', name = 'lecturers_subject'),  
    
  # Program management
  url(r'^program$', 'skoolmaster.syllabus.views.program_management', name = 'program_management'),
  url(r'^program/(?P<program_id>[a-zA-Z0-9]+)$', 'skoolmaster.syllabus.views.program_management', name = 'program_display'),
  url(r'^program/save/module/(?P<program_id>[a-zA-Z0-9]+),(?P<module_id>\d+)$', 'skoolmaster.syllabus.views.program_module_save', name = 'program_module_save'),
  url(r'^program/save/elective/(?P<program_id>[a-zA-Z0-9]+),(?P<year_id>\d+)$', 'skoolmaster.syllabus.views.program_elective_save', name = 'program_elective_save'),
  url(r'^program/year/(?P<program_id>[a-zA-Z0-9]+)$', 'skoolmaster.syllabus.views.program_year', name = 'program_year_add'),
  url(r'^program/year/(?P<program_id>[a-zA-Z0-9]+),(?P<year_id>\d+)$', 'skoolmaster.syllabus.views.program_year', name = 'program_year_del'),
  url(r'^program/module/(?P<program_id>[a-zA-Z0-9]+),(?P<year_id>\d+)$', 'skoolmaster.syllabus.views.program_module', name = 'program_module_add'),
  url(r'^program/module/(?P<program_id>[a-zA-Z0-9]+),(?P<year_id>\d+),(?P<module_id>\d+)$', 'skoolmaster.syllabus.views.program_module', name = 'program_module_del'),
  
  # School year management
  url(r'^school_year/create$', 'skoolmaster.syllabus.views.create_school_year', name = 'create_school_year'),
  url(r'^school_year$', 'skoolmaster.syllabus.views.school_year_display', name = 'school_year_display'),
  url(r'^school_year/(?P<school_year_id>[0-9]+)/(?P<action>(edit|del))$', 'skoolmaster.syllabus.views.school_year_edit', name = 'school_year'),
  
  # Enrollment management
  url(r'^enrollment/add$', 'skoolmaster.general.views.enrollment_add', name = 'enrollment_add'),
  url(r'^enrollment/add/(?P<program_id>[a-zA-Z0-9]+)$', 'skoolmaster.general.views.enrollment_add', name = 'enrollment_add'),
  url(r'^enrollment/add/(?P<program_id>[a-zA-Z0-9]+)/(?P<facultyyear_id>[0-9]+)$', 'skoolmaster.general.views.enrollment_add', name = 'enrollment_add'),
  url(r'^enrollment/add/(?P<program_id>[a-zA-Z0-9]+)/(?P<facultyyear_id>[0-9]+)/form$', 'skoolmaster.general.views.enrollment_add_form', name = 'enrollment_add_form'),
  url(r'^enrollment/add/(?P<program_id>[a-zA-Z0-9]+)/(?P<facultyyear_id>[0-9]+)/(?P<student_number>[0-9]*)/form$', 'skoolmaster.general.views.enrollment_add_form', name = 'enrollment_add_form'),
  
  url(r'^enrollment/subjects/manage$', 'skoolmaster.general.views.subjects_manage', name = 'subjects_manage'),
  url(r'^enrollment/subjects/manage/(?P<student_number>\d+)$', 'skoolmaster.general.views.subjects_manage', name = 'subjects_manage'),
  url(r'^enrollment/subjects/manage/(?P<student_number>\d+)/(?P<school_year>[0-9/]+)$', 'skoolmaster.general.views.subjects_manage', name = 'subjects_manage'),
  
  # Student personal data
  url(r'^personal_data/(?P<user_id>[a-zA-Z0-9]+)$', 'skoolmaster.general.views.personal_data', name = 'personal_data')
)

# Use internal Django server to serve static files in debug mode
if settings.DEBUG:
  urlpatterns += patterns('',
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes' : True})
  )
